<?php
class CleanAction extends BaseAction{
	public function index(){
		$count = D('Feed')->count();
		$this->assign('count', $count);
		
		$this->display();
	}
	
	function doCleanFeed(){
		$type = $_POST['dataType'];		
		
		switch ($type){
			case '清除30天前的动态':  $date = 30;  break;
			case '清除60天前的动态':  $date = 60;  break;
			case '清除90天前的动态':  $date = 90;  break;
			case '清除180天前的动态': $date = 180; break;
			case '清除360天前的动态': $date = 360; break;
			default: $date = 360;
		}
		
		$time = mktime(0,0,0,date('m'), date('d')-$date, date('Y'));
		
		$map['cTime'] = array('exp', "<$time");
		$list = D('Feed')->where($map)->field('id')->findall();
		$feed = getSubByKey($list, 'id');
		$feed = implode(',', $feed);
		
		if(!empty($feed)){
			$res = D('FeedIgnore')->where("feedid IN( $feed )")->delete();
			$res = D('Feed')->where("id IN( $feed )")->delete();
		}		
		if($res){
			addLog($this->mid, array('info'=>$type), 'clean_docleanfeed');
			
			$this->success('清除成功');
		}else{
			$this->error('已经没有可清除的数据了');
		}
	}
}
?>